package models

const STATUS = 1

type User struct {
	BaseModel
	UserName string  `json:"userName" gorm:"not null;"` //用户名
	Password string  `json:"-" gorm:"not null;"`        //密码
	Email    *string `json:"email" gorm:"unique"`       //邮箱
	Phone    string  `json:"phone" gorm:"unique;"`      //手机号
	Status   int     `json:"status"`                    //用户状态
	Auth     int     `json:"auth"`                      //用户权限
}

func (u *User) CreateTable() {
	err := DB.AutoMigrate(&User{})
	if err != nil {
		panic("创建用户表失败:" + err.Error())
	}
}

func (u *User) Add() error {
	u.Status = STATUS
	return DB.Create(u).Error
}

func (u *User) Find() ([]User, error) {
	var user []User
	result := DB.Where(u).Find(&user)
	return user, result.Error
}
